<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php 
include_once('..\\common.php');
//  防止全局变量造成安全隐患 
$admin = false; 
//  启动会话，这步必不可少 
CheckAdminLogon();
?>

<?php

$posts = $_POST; 
//  清除一些空白符号 
foreach ($posts as $key => $value) {
    $posts[$key] = trim($value); 
} 


$username = $posts["username"]; 
$password = $posts["password"];

//echo $username;
//echo "</p>";
//echo $password;

$DB = DBConnect();

$selectquery = "SELECT id FROM saler WHERE `name` = '$username'";
//echo $selectquery;

$result = mysql_query($selectquery,$DB);

if( mysql_affected_rows() && mysql_fetch_row($result) )
{
	echo "用户名已存在！";
}
else
{	
	$query = "INSERT saler SET name ='$username' , password='$password' "; 
	$result = mysql_query($query,$DB);

	if (!empty($result))
	{     
 	  echo "注册成功！";
	  header("Location:index.php");
	}
	else 
	{ 
   	 die("新建用户错误！"); 
	} 

}
?>



</body>
</html>